package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.DiseaseService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.DiseaseReportVO;
import com.lanchetech.entity.Disease;
import com.lanchetech.entity.DiseaseReportHistory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@Api(value = "疾病管理", tags = "疾病管理")
@RequestMapping("/api/disease")
@RestController
public class DiseaseController {

    @Autowired
    DiseaseService diseaseService;

    @OperatorLog("编辑疾病")
    @ApiOperation("编辑疾病")
    @PreAuthorize("hasAuthority('disease.index.edit.auth')")
    @PostMapping("/editDisease")
    public BaseResp editDisease(@RequestBody Disease req) {
        return diseaseService.editDisease(req);
    }

    @ApiOperation(value = "获取疾病分页", notes = "name 疾病名称 search 字母")
    @PreAuthorize("hasAuthority('disease.index')")
    @PostMapping("/getDiseasePage")
    public ResultData<BasePageResp<Disease>> getDiseasePage(@RequestBody PageReq req) {
        return diseaseService.getDiseasePage(req);
    }

    @ApiOperation("获取疾病详情")
    @PreAuthorize("hasAuthority('disease.edit')")
    @GetMapping("/getDiseaseDetail")
    public ResultData<Disease> getDiseaseDetail(@RequestParam("id") Long id) {
        return diseaseService.getDiseaseDetail(id);
    }

    @OperatorLog("删除疾病")
    @ApiOperation("删除疾病")
    @PreAuthorize("hasAuthority('disease.index.edit.auth')")
    @GetMapping("/deleteDisease")
    public BaseResp deleteDisease(@RequestParam("id") Long id) {
        return diseaseService.deleteDisease(id);
    }

    @ApiOperation(value = "获取疾病报告分页", notes = "userId 用户编号 name 姓名 search 当前疾病名称中模糊搜索")
    @PreAuthorize("hasAuthority('disease.report')")
    @PostMapping("/getDiseaseReportPage")
    public ResultData<BasePageResp<DiseaseReportVO>> getDiseaseReportPage(@RequestBody PageReq req) {
        return diseaseService.getDiseaseReportPage(req);
    }

    @ApiOperation(value = "获取指定用户的历史疾病报告列表", notes = "userId 用户编号 search 当前疾病名称中模糊搜索")
    @PreAuthorize("hasAuthority('disease.history')")
    @PostMapping("/getDiseaseReportHistory")
    public ResultData<BasePageResp<DiseaseReportHistory>> getDiseaseReportHistory(@RequestBody PageReq req) {
        return diseaseService.getDiseaseReportHistory(req);
    }

}
